<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDriversTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('drivers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('user_id')->index()->comment('用户ID');
            $table->char('phone', 11)->comment('手机号');
            $table->string('real_name', 50)->comment('真实姓名');
            $table->enum('sex', [1, 2, 3])->nullable()->default(3)->comment('性别：1-男，2-女，3-保密');
            $table->bigInteger('head_image')->nullable()->comment('头像');
            $table->string('linkman', 50)->nullable()->comment('紧急联系人');
            $table->char('linkphone', 11)->nullable()->comment('紧急联系人电话');
            $table->string('address')->nullable()->comment('现住地址');
            $table->string('identity', 30)->nullable()->comment('身份证号');
            $table->json('identity_photo')->nullable()->comment('身份证照片');
            $table->date('identity_end')->nullable()->comment('身份证有效期');
            $table->bigInteger('company_id')->comment('所属公司');
            $table->json('work_scope')->nullable()->comment('业务范围');
            $table->integer('province')->nullable()->comment('接单省份');
            $table->integer('city')->nullable()->comment('接单城市');
            $table->timestamp('entry_time')->nullable()->comment('入职时间');
            $table->bigInteger('referrer_id')->nullable()->comment('推荐人');
            $table->enum('safety_train', [1, 0])->nullable()->default(0)->comment('安全培训：0-未培训，1-已培训');
            $table->integer('licence_id')->nullable()->comment('驾照类型');
            $table->integer('driving_years')->nullable()->default(1)->comment('驾龄');
            $table->json('licence_photo')->nullable()->comment('驾照照片');
            $table->date('license_first')->nullable()->comment('初次领证日期');
            $table->date('license_start')->nullable()->comment('驾照有效期起');
            $table->date('licence_end')->nullable()->comment('驾照有效期止');
            $table->enum('status', [1, 2, 3, 4, 5, -1])->default(-1)->comment('状态：1-待审核，2-在职，3-驳回，4-冻结，5-离职，-1-未申请');
            $table->string('versions', 20)->nullable()->comment('版本号');
            $table->timestamp('last_login')->nullable()->comment('最后登陆时间');
            $table->timestamp('last_take')->nullable()->comment('最后接单时间');
            $table->enum('source', [1, 2, 3])->nullable()->default(1)->comment('来源：1-自然申请，2-导入 3-后台添加');
            $table->enum('receiving_status', [1, 2])->default(1)->comment('来源：1-未接单，2-接单中');
            $table->integer('sort')->default(0)->comment('排序');
            $table->timestamps();
            $table->softDeletes();
        });
        \DB::statement("ALTER TABLE `drivers` comment '司机申请表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('drivers');
    }
}
